package com.ninthgroup.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.ninthgroup.entity.TechnicalOffice;
import com.ninthgroup.mapper.TechnicalOfficeMapper;
import com.ninthgroup.service.TechnicalOfficeService;
import com.ninthgroup.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Student A Wei
 * @date ：Created in 2022/10/18 16:38
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class TechnicalOfficeServiceImpl implements TechnicalOfficeService {
    @Autowired
    private TechnicalOfficeMapper technicalOfficeMapper;

    //查询科室表
    @Override
    public Result selectAll(Integer currentPage,Integer pageSize,String tName,Integer tStatus) {

        PageHelper.startPage(currentPage,pageSize);
        List<TechnicalOffice> to = technicalOfficeMapper.selectByCondition(tName,tStatus);
        PageInfo<TechnicalOffice> pageInfo=new PageInfo<>(to);
        return new Result(200, "查询成功", pageInfo);
    }

    //科室表的删除
    @Override
    public Result deleteByTechnicalOfficeId(Integer TechnicalOfficeId) {
        technicalOfficeMapper.deleteByPrimaryKey(TechnicalOfficeId);
        System.out.println("TechnicalOfficeId = " + TechnicalOfficeId);
        return new Result(200, "删除成功");
    }

    //科室表的添加
    @Override
    public Result insertAdd(TechnicalOffice technicalOffice) {
        int insert = technicalOfficeMapper.insertSelective(technicalOffice);
        return new Result(200, "添加成功");
    }

    //科室的修改
    @Override
    public Result update(TechnicalOffice technicalOffice) {
        int update = technicalOfficeMapper.updateByPrimaryKeySelective(technicalOffice);
        return new Result(200,"修改成功");
    }

    @Override
    public Result updateStatus(Integer tId, Integer tStatus) {
        if (tStatus ==0){
            TechnicalOffice technicalOffice = new TechnicalOffice();
            technicalOffice.settId(tId);
            technicalOffice.settStatus(1);
            int i = technicalOfficeMapper.updateByPrimaryKeySelective(technicalOffice);
            return new Result(200,"修改状态成功(裁撤科室变正常)");
        }else{
            TechnicalOffice technicalOffice = new TechnicalOffice();
            technicalOffice.settId(tId);
            technicalOffice.settStatus(0);
            int i = technicalOfficeMapper.updateByPrimaryKeySelective(technicalOffice);
            return new Result(200,"修改状态成功(正常变裁撤科室)");
        }
    }
}